package org.hxyjs.service.impl;


import org.hxyjs.dao.AdvertisingtypeDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Advertisingtype;
import org.hxyjs.entity.Advertisingtype;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AdvertisingtypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("AdvertisingtypeService")
public class AdvertisingtypeServiceImpl implements AdvertisingtypeService {
    @Resource
    AdvertisingtypeDao advertisingtypeDao;
    @Override
    public DTO<Advertisingtype> getAllAdvertisingtypes()  throws Exception{
        List<Advertisingtype> advertisingtypes = advertisingtypeDao.getAllAdvertisingtypes();
        MessageEnum messageEnum  = Optional.ofNullable(advertisingtypes).isPresent()?MessageEnum.GETADVERTISINGTYPESUCCESS: MessageEnum.GETADVERTISINGTYPEFAIL;
        return new DTO<Advertisingtype>(messageEnum.getCode(),messageEnum.getMessage(),advertisingtypes);
    }

    @Override
    public DTO<Advertisingtype> deleteAdvertisingtypeByAdvrno(String advrno)  throws Exception{
        Integer result = advertisingtypeDao.deleteAdvertisingtypeByAdvrno(advrno);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADVERTISINGTYPESUCCESS:MessageEnum.DELETEADVERTISINGTYPEFAIL;
        return new DTO<Advertisingtype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Advertisingtype> updateAdvertisingtypeByAdvrno(Advertisingtype advertisingtype)  throws Exception{
        Integer result = advertisingtypeDao.updateAdvertisingtypeByAdvrno(advertisingtype);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADVERTISINGTYPESUCCESS:MessageEnum.UPDATEADVERTISINGTYPEFAIL;
        return new DTO<Advertisingtype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Advertisingtype> addAdvertisingtype(Advertisingtype advertisingtype) throws Exception {
        Integer result = advertisingtypeDao.addAdvertisingtype(advertisingtype);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDADVERTISINGTYPESUCCESS:MessageEnum.ADDADVERTISINGTYPEFAIL;
        return new DTO<Advertisingtype>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Advertisingtype> getAdvertisingtypeByPage(PageInfo pageInfo ) throws Exception {
        List<Advertisingtype> advertisingtypes = advertisingtypeDao.getAdvertisingtypeByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(advertisingtypes).isPresent()?MessageEnum.GETADVERTISINGTYPESUCCESS: MessageEnum.GETADVERTISINGTYPEFAIL;
        return new DTO<Advertisingtype>(messageEnum.getCode(),messageEnum.getMessage(),advertisingtypes,pageInfo);
    }
}
